<template>
	<view class="rectificationContent">
		<view class="upper">
			<CommonNavBar title="问题整改" :showSearch="true" @search="open"></CommonNavBar>
			<view class="step">
				<view v-for="(tabs,index) in stepList" :key="index" @click="stepActive(index)">
					<view :class="{'active': index == tabIndex  || (tabIndex == 10 && index == stepList.length - 1)}">
						{{ tabs.step }}
					</view>
				</view>
			</view>
		</view>
		<view class="centre" >
			<z-paging
				ref="paging"
				autowire-list-name="rectificationList" 
				autowire-query-name="listData" style="margin-top: 200rpx;"
			  > 
					<view class="li" v-for="(list,index) in rectificationList" :key="index" @click="rectificationActive(list.ID,list.CHECK_STATUS,list.IS_AUTHORITY,list.id)">
						<view v-if="stepList[tabIndex].checkType === 'bb'">
							<view class="h1">{{ index+1 }}.{{ list.entName }}</view>
							<view class="h2">完成时间:{{ list.fillingTime }}</view>
							<view class="h2">是否既定任务:{{ list.ableDel === '0' ? '既定任务' : '自行创建任务' }}</view>
							<view class="h2">督导顺序号:本季度第{{ list.orderNum }}次督导</view>
							<view class="h2">督导主体唯一编码:{{ list.entUniqueCode }}</view>
							<view class="h2">行政区划:{{ list.regionalismRealCode }}</view>
							<view class="h2">督导时主体的级别:{{ list.grade }}</view>
							<view class="h2">督导时的主体状态:{{ list.entState === '1' ? '在产在营' : 
															   list.entState === '2' ? '临时停产停业' : 
															   list.entState === '3' ? '长期停产停业' : 
															   list.entState === '4' ? '一址多证（旧证）' : 
															   list.entState === '5' ? '失联' : '' }}
							</view>
							<view class="h2">督导人员姓名:{{ list.name }}</view>
							<view class="h2">任务状态:{{ list.tastState === '0' ? '未完成 ' : '完成 ' }}</view>
							<view class="h2">年度:{{ list.yearInfo }}</view>
							<view class="h2">季度:{{ list.quarter }}</view>
							<view class="h2">督导人唯一编码:{{ list.supUniqueCode }}</view>
						</view>
						<view v-else>
							<view class="float">{{ list.PROCESS_NAME }}</view>
							<view class="h1">{{ index+1 }}.{{ list.COMPANY_NAME }}</view>
							<view class="h2">经营状态:{{ list.MANAGE_STATUS === '0' ? '正常' : list.MANAGE_STATUS === '1' ? '异常' : '-' }}</view>
							<view class="h2">整改时限:{{ list.RECTIFICATION_TIME_LIMIT }}</view>
							<view class="h2" :class="{ 'no' : list.PROBLEM_NUM > 0 }">问题数目:<text>{{ list.PROBLEM_NUM == 0 ? '-' : list.PROBLEM_NUM }}</text></view>
							<view class="h2">业态:{{ list.BUSINESS_TYPE }}{{ list.BUSINESS_TYPE_TWO | businessTwoFilter }}</view>
							<view class="h2">许可证号:{{ list.LICENSE }}</view>
							<view class="h2">所属区局:{{ list.DEPT_QU_NAME }}</view>
							<view class="h2">监管单位:{{ list.DEPT_NAME }}</view>
							<view class="order" :class="{ 'yes' : list.CHECK_STATUS !== '1' }">
								{{ list.CHECK_STATUS  | checkStatusFilter }}
								<view class="arrow"></view>
							</view>
						</view>
					</view>
			</z-paging>
			
		</view>
		 <view class="fixed">当前已搜索到{{ total }}条数据</view> 
		 <CommonSearchCompontVue ref="CommonSearchCompontVueRef"  @seacharResult="seacharResult" :showTime="false" :showRecificationStatus="true"
		  :showSearchCompont="showSearchCompont"  ></CommonSearchCompontVue>
	</view>
</template>

<script>
	import CommonSearchCompontVue from '@/components/CommonSearchCompont.vue'
	import CommonNavBar from '@/components/CommonNavBar.vue'
	 
	export default {
		components: {
			CommonSearchCompontVue,
			CommonNavBar
		},
		data() {
			return { 
				image: '/static/img/screen.png',
				stepList: [{
					step: '日常检查',
					checkType: '1',
					active: true
				},  {
					step: '双随机检查',
					checkType: '2',
					active: false
				},  {
					step: '飞行检查',
					checkType: '3',
					active: false
				}, {
					step: '体系检查',
					checkType: '4',
					active: false
				}/* , {
					step: '包保责任',
					checkType: 'bb',
					active: false
				} */],
				tabIndex:0,
				rectificationList:[],
				total: 0,
				showSearchCompont:false, 
				searchParams:{ 
					checkType:1,
					pageNum:1,
					pageSize:10,
				}
			}
		},
		onLoad(options) {
			this.searchParams.checkStatus = options.status == null ? '' : options.status; 
		},
		onReady(){
			this.$refs.CommonSearchCompontVueRef.setCheckStatus(this.searchParams.checkStatus+""); 
		},
		filters:{
			businessTwoFilter(value){
				if(value == undefined){
					return '';
				} else {
					return '-' + value
				}
			},
			checkStatusFilter(value){ 
				if(value == undefined){
					return '待整改';
				} else if(value === '1'){
					return '待整改';
				} else if(value === '2'){
					return '已整改';
				} else if(value === '3'){
					return '未通过';
				}
			}
		},  
		methods: {
			goBack() {
				uni.navigateBack();
			},
			seacharResult(e){
				//检索条件点击确定或者删除的时候在执行
				this.showSearchCompont =  false;
				if(e.search){
					this.searchParams = e;
					this.$refs.paging.reload();
				} 
			},
			stepActive(index) {
				if(index == 4){
					//包保责任暂时没有业务，就是为了占用位置，这里让其查不出数据即可
					this.tabIndex = 10;
				} else{
					this.tabIndex = index
				}
				this.$refs.paging.reload() 
			},
			open() { 
				this.showSearchCompont = true
			},   
			async listData(pageNo, pageSize) {
				this.searchParams.pageNum = pageNo;
				this.searchParams.pageSize= pageSize;
				this.searchParams.checkType =  this.stepList[this.tabIndex].checkType === 'bb' ? 'specialType' :  this.stepList[this.tabIndex].checkType;
				
				try { 
					let res;
					 //检查整改信息
					// const res = await uni.$api.getRectificationPage(this.searchParams);
					if (this.stepList[this.tabIndex].checkType === 'bb') {
						// 调用新的接口
						res = await uni.$api.getBaobaoListByCompanyCode();
						console.log('res', res.data.data)
					} else {
						// 原来的接口请求
						res = await uni.$api.getRectificationPage(this.searchParams);
					}
					this.$refs.paging.completeByKey(res.data.data.records,this.tabIndex);
					this.total = res.data.data.total
				}  catch (error) {
					console.error(error)
					 this.$refs.paging.complete(false);
				}
				
			},
			rectificationActive(id,status,isAuthority,bbId) {
				const  that = this;
				if(bbId != '' && bbId != undefined) {
					uni.navigateTo({
						url: '/pages/rectification/guaranteedActive?bbId=' + bbId
					}) 
				}else { 
					uni.navigateTo({
						url: '/pages/rectification/rectificationActive?rectificationId=' + id + "&detail="+ (status != '1')// || isAuthority != '1')
						,events: {
							// 为指定事件添加一个监听器，获取被打开页面传送到当前页面的数据
							reloadList: function(data) {
							   that.$refs.paging.reload();
							} 
						}
					}) 
				}
			}
		},
		watch: {
			
		},
	}
</script>

<style lang="scss">
	.rectificationContent {
		background: #F9F9F9;
		height: calc(100vh - 195rpx);

		.upper {
			position: fixed;
			z-index: 1;
			top: 0;
			left: 0;
			width: 100%;

			.title {
				background: url('../../static/img/inspectBg.png');
				background-size: cover;
				width: 100%;
				height: 115rpx;
				line-height: 115rpx;
				position: relative;
				display: flex;
				justify-content: center;

				.arrow {
					position: absolute;
					left: 33rpx;
					top: 50%;
					transform: translate(0%, -50%);
					width: 100rpx;
					height: 100rpx;
					 
					&::before {
						display: block;
						content: "";
						position: absolute;
						top: 50%;
						left: 0%;
						width: 20rpx;
						height: 20rpx;
						border-left: 1px solid #fff;
						border-top: 1px solid #fff;
						transform: translate(0%, -50%) rotate(-45deg);
					}
				}

				text {
					font-size: 30rpx;
					font-family: PingFangSC-Medium, PingFang SC;
					font-weight: 500;
					color: #FFFFFF;
					letter-spacing: 1px;
				}

				.screen {
					position: absolute;
					right: 30rpx;
					top: 50%;
					transform: translate(0%, -50%);
					width: 35rpx;
					height: 33rpx;
				}
			}

			.step {
				display: flex;
				justify-content: space-evenly;
				height: 80rpx;
				line-height: 80rpx;
				background: #F9F9F9;

				view {
					position: relative;
					font-size: 25rpx;
					font-family: PingFangSC-Regular, PingFang SC;
					font-weight: 400;
					color: #999999;
					width: 100%;
					text-align: center;

					&.active {
						color: #0552A9;

						&::before {
							display: block;
							content: "";
							position: absolute;
							left: 50%;
							bottom: 0%;
							transform: translate(-50%, 0%);
							width: 100rpx;
							height: 5rpx;
							background: #0552A9;
						}
					}
				}
			}
		}

		.centre {
			margin: 195rpx 0 0 0;
			padding: 0 17.5rpx;
			height: calc(100vh - 280rpx);
			overflow-x: hidden;

			.li {
				background: linear-gradient(180deg, #FFFFFF 0%, #FFFFFF 100%);
				box-shadow: 0rpx 8rpx 15rpx 0rpx rgba(0, 0, 0, 0.05);
				border-radius: 15rpx;
				padding: 30rpx 30rpx 21rpx 28rpx;
				position: relative;
				margin: 13rpx 20rpx 0;

				.float {
					position: absolute;
					top: 0;
					right: 0;
					// width: 97rpx;
					padding: 0 10rpx;
					height: 46rpx;
					line-height: 46rpx;
					background: linear-gradient(180deg, #5DA1FF 0%, #0054C9 100%);
					border-radius: 0rpx 11rpx 0rpx 11rpx;
					font-size: 18rpx;
					font-family: PingFangSC-Medium, PingFang SC;
					font-weight: 500;
					color: #FFFFFF;
					text-align: center;
				}

				.h1 {
					font-size: 24rpx;
					font-family: PingFangSC-Medium, PingFang SC;
					font-weight: 500;
					color: #333333;
					line-height: 1;
					margin: 0 0 14rpx 0;
				}

				.h2 {
					font-size: 19rpx;
					font-family: PingFangSC-Regular, PingFang SC;
					font-weight: 400;
					color: #666666;
					line-height: 1;
					margin: 12rpx auto;
					
					text {
						color: #00BE8C;
					}
					
					&.no {
						
						text {
							color: #FF3829;
						}
					}
				}

				.order {
					width: 121rpx;
					height: 46rpx;
					line-height: 46rpx;
					text-align: center;
					background: #FF594C;
					border-radius: 9rpx;
					font-size: 18rpx;
					font-family: PingFangSC-Medium, PingFang SC;
					font-weight: 500;
					color: #FFFFFF;
					margin: 16rpx 0 0 0;
					position: relative;
					
					&.yes {
						background: #00BE8C;
					}
					
					.arrow {
						width: 0;
						height: 0;
						border-top: 4px solid transparent;
						border-bottom: 4px solid transparent;
						border-left: 5px solid #fff;
						position: absolute;
						top: 50%;
						right: 8rpx;
						-webkit-transform: translate(-50%, -50%);
						transform: translate(-50%, -50%);
					}
				}
			}
		}

		.fixed {
			position: fixed;
			left: 50%;
			bottom: 26rpx;
			transform: translate(-50%, 0);
			width: 100%;
			text-align: center;
			font-size: 18rpx;
			font-family: PingFangSC-Regular, PingFang SC;
			font-weight: 400;
			color: #A7A7A7;
		}

		.popupContent {
			background: #FFFFFF;
			border-radius: 20rpx 20rpx 0 0;

			.title {
				width: 100%;
				height: 80rpx;
				line-height: 80rpx;
				background: url('../../static/img/popupTitle.png') no-repeat center center;
				background-size: cover;
				font-size: 25rpx;
				font-family: PingFangSC-Medium, PingFang SC;
				font-weight: 500;
				color: #FFFFFF;
				text-indent: 45rpx;
			}

			.ul {

				.li {
					padding: 0 45rpx;
					margin: 0 auto;
					display: flex;
					justify-content: space-between;
					align-items: center;
					min-height: 68rpx;
					line-height: 68rpx;
					border-bottom: 1px solid #d6d6d6;
						
					.left {
						font-size: 21rpx;
						font-family: PingFangSC-Regular, PingFang SC;
						font-weight: 400;
						color: #333333;
					}
						
					.right {
						
						input {
							font-size: 21rpx;
							font-family: PingFangSC-Regular, PingFang SC;
							font-weight: 400;
							color: #999999;
							width: 420rpx;
							text-indent: 20rpx;
						}
						
						.placeholder-class {
							color: #999999;
						}
						
						.uni-stat__select {
							width: 420rpx;

							/deep/.uni-select {
								border: none;
							}
						}
						
						.uni-date {
							width: 420rpx;
							
							/deep/.uni-date-editor--x {
								border: none;
							}
						}
					}
					
					&:nth-child(odd) {
						background: #F9F9F9;
					}
					
					&:last-child {
						border-bottom: none;
					}
				}
			}
			
			.button {
				margin: 58rpx auto 0;
				padding: 0 95rpx 24rpx 95rpx;
				display: flex;
				
				button {
					width: 269rpx;
					height: 55rpx;
					line-height: 55rpx;
					background: #0552A9;
					border-radius: 10rpx;
					font-size: 20rpx;
					font-family: PingFangSC-Regular, PingFang SC;
					font-weight: 400;
				
					&.determine {
						color: #fff;
					}
					
					&.cancellation {
						background: none;
						border: 1rpx solid #979797;
						color: #979797;
					}
				}
			}
		}
	}
</style>